

package cn.shengchao.controler.user;

import cn.shengchao.examstar.distribute.infrastrure.po.DistributeNodeInfo;
import cn.shengchao.examstar.distribute.infrastrure.service.DistributeNodeInfoService;
import cn.shengchao.examstar.rpc.distribute.enums.DistributeSaleRoleEnum;
import cn.shengchao.examstart.user.acl.adapters.message.MemberStudent;
import cn.shengchao.service.MemberAppService;
import cn.shengchao.examstar.product.acl.ports.repositories.message.MemberCourseOrder;
import cn.shengchao.service.vo.MemberVo;
import cn.shengchao.util.helper.LoginHelper;
import com.google.common.collect.Maps;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "会员")
@Slf4j
@RestController
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/member")
public class MemberController {

    @Autowired
    private DistributeNodeInfoService distributeNodeInfoService;

    @Autowired
    private MemberAppService memberAppService;

    @GetMapping("isMember")
    public Map.Entry<String, Boolean> getMember() {
        DistributeNodeInfo distributeNodeInfo = distributeNodeInfoService.getDistributeNodeInfo(LoginHelper.getUserId(), DistributeSaleRoleEnum.ROLE_SLMB);
        return Maps.immutableEntry("isMember", distributeNodeInfo != null);
    }

    @GetMapping
    public MemberVo getMemberInfo() {
        return memberAppService.getMemberInfo(LoginHelper.getUserId());
    }

    @GetMapping("course")
    public List<MemberCourseOrder> getMemberCourse(@RequestParam(required = false) String courseName
            , @RequestParam(required = false, defaultValue = "") String sort) {
        return memberAppService.getMemberCourse(LoginHelper.getUserId(), courseName, sort);
    }

    @GetMapping("student")
    public List<MemberStudent> getMemberStudent(@RequestParam(required = false) String searchValue) {
        return memberAppService.getMemberStudent(LoginHelper.getUserId(), searchValue);
    }


}
